package com.yunhe.util;
import java.sql.*;
import java.sql.Connection;

public class DaoFactory {
    public static Connection getConnection() {
        String driver = "oracle.jdbc.driver.OracleDriver";
        String url = "jdbc:oracle:thin:@localhost:1521:orcl";
        String user = "scott";
        String pwd = "tiger";
        Connection conn = null;
        try {
            Class.forName(driver);
            conn= DriverManager.getConnection(url,user,pwd);
        }catch(SQLException e){
            e.printStackTrace();
        }catch(ClassNotFoundException e){
            System.out.println(e.getMessage());
        }
        return conn;
    }

    public static void closeAll(Connection conn, Statement st, ResultSet rs){
        try{
            if(rs!=null){
                rs.close();
            }
            if(st!=null){
                st.close();
            }
            if(conn !=null){
                conn.close();
            }
        }catch(SQLException e){
            e.printStackTrace();
        }
    }
}
